<h1>Earned Revenue Report</h1>
<div class="form">
    <?php
    $year = date('Y');
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'earn-revenue-form',
        'method' => 'get'
            ));
    ?>

    <div class="row">
        <?php echo CHtml::label('Start date', 'form[startdate]'); ?>

        <?php
        $this->widget('zii.widgets.jui.CJuiDatePicker', array(
            'name' => 'form[startdate]',
            'value' => "01/01/$year",
                //  'options' => array('startdate' => 'm-d-yy'),
        ));
        ?>
    </div>
    <div class="row">
        <?php echo CHtml::label('End date', 'form[enddate]'); ?>
        <?php
        $this->widget('zii.widgets.jui.CJuiDatePicker', array(
            'name' => 'form[enddate]',
            'value' => CTimestamp::formatDate('m/d/Y', time()),
                //  'options' => array('start' => 'm-d-yy'),
        ));
        ?>
    </div>
    <div class="row">
        <?php echo CHtml::label('Contract Type', 'form[ctype]'); ?>
        <br clear="both"/>
        <div class="data-model" style="padding-left: 20px;">
            <?php
            $data = array(0 => 'All Contract Types');
            $data += ContractType::getListData();
            ?>
            <?php
            foreach ($data as $key => $value):
                ?>
                <label><?= $value ?></label>
                <input class="ctype" type="checkbox" id ="form_ctype_<?= $key ?>" name="form[ctype][<?= $key ?>]">

                <br clear="both"/>
            <?php endforeach; ?>    
        </div>
    </div>
    <div class="row_buttons">
        <?php echo CHtml::submitButton('Submit'); ?>
    </div>
    <?php $this->endWidget(); ?>
</div>
<script>

    $('#form_ctype_0').change(function (e) {
        var all = this.checked;
        if(all){
            $("input.ctype").each(function(){
         
                this.checked = 'checked'
            })
        } 
    });
    $('input.ctype').change(function (e) {
  
        var counter=0;
       
        $("input.ctype").each(function(){
          if( this.checked) counter++;
           
        })
        if (counter==<?=count(ContractType::getListData())?>){
             $('#form_ctype_0').attr( 'checked', true);
        }
       
    });
    
</script>